package Utils;

import org.hibernate.Session;  
import org.hibernate.SessionFactory;  
import org.hibernate.cfg.Configuration;  
import org.hibernate.service.ServiceRegistry;  
import org.hibernate.service.ServiceRegistryBuilder;  

import Model.Livro;
      
      
    public class HibernateUtil {  
      
        private static SessionFactory factory;  
      
        static {  
            //Configuration cfg = new Configuration(); // Nao preciso chamar .configure(), porque nao uso hibernate.cfg.xml, uso hibernate.properties
            Configuration cfg = new Configuration().configure(); 
            cfg.addAnnotatedClass(Livro.class); // Aqui coloco as classes que tem as anotacoes  
            ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();  
            factory = cfg.buildSessionFactory(serviceRegistry);  
      
        }  
          
        public static Session getSession() {  
            return factory.openSession();  
        }  
          
    }  